package com.crm.controller;

import com.crm.dto.MenuDto;
import com.crm.result.AjaxResult;
import com.crm.result.Result;
import com.crm.service.MenuService;
import com.crm.vo.SysMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单管理
 */
@RestController
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * 菜单列表
     * @param menuDto
     * @return
     */
    @GetMapping("/system/menu/list")
    public Result list(MenuDto menuDto) {
        List<SysMenu> list = menuService.selectMenu(menuDto);
        return Result.success(list);
    }

    /**
     * 查询菜单树形结构
     * @return
     */
    @GetMapping("/system/menu/treeselect")
    public Result treeselect(){
        //todo 还没写
        List<SysMenu> list = menuService.selectMenuTree();
        return Result.success();
    }

    @GetMapping("/system/notice/list/{id}")
    public Result notice(@PathVariable Integer id){
        return Result.success();
    }

    /**
     * 新增菜单
     * @param menu
     * @return
     */
    @PostMapping("/system/menu")
    public AjaxResult addMenu(@RequestBody SysMenu menu){
        menuService.addMenu(menu);
        return AjaxResult.success();
    }

    /**
     * 查询回显
     * @param id
     * @return
     */
    @GetMapping("/system/menu/{id}")
    public Result<SysMenu> getMenuById(@PathVariable Long id){
        return Result.success(menuService.getMenuById(id));
    }


    /**
     * 修改菜单
     * @param menu
     * @return
     */
    @PutMapping("/system/menu")
    public AjaxResult updateMenu(@RequestBody SysMenu menu){
        menuService.updateMenu(menu);
        return AjaxResult.success();
    }

    /**
     * 删除菜单
     * @param id
     * @return
     */
    @DeleteMapping("/system/menu/{id}")
    public AjaxResult deleteMenu(@PathVariable Long id){
        menuService.deleteMenu(id);
        return AjaxResult.success();
    }
}
